﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Exp.BillDLL.biz;
using System.IO;
using System.Windows.Forms;
using TT.Module.sysLogin;
using TT.ORM;

namespace ExpBillMain
{
    public class initLoad
    {
        bizExpBill bzExpBill;

        public initLoad()
        {
            #region 登陆
            string oraclePath = System.Windows.Forms.Application.StartupPath + @"\OraBin";
            if (File.Exists(oraclePath + @"\tnsnames.ora")) //如果存在此文件
            {
                Environment.SetEnvironmentVariable("PATH", oraclePath, EnvironmentVariableTarget.Process);
                Environment.SetEnvironmentVariable("NLS_LANG", "AMERICAN_AMERICA.WE8ISO8859P1", EnvironmentVariableTarget.Process);
                Environment.SetEnvironmentVariable("TNS_ADMIN", oraclePath, EnvironmentVariableTarget.Process);
            }
            bool sLogMsg = APP.Login("ctms", "ds1", "123123", "SysExp");

            if (sLogMsg == false)
            {
                MessageBox.Show("数据库连接错误，请检查网络。");
                return;
            }
            #endregion

            string sPC_Name = System.Net.Dns.GetHostName();
            if (sPC_Name != "JVC-PC" && sPC_Name != "WH")
            {
                APP.SqlHelp.WriteLogEnabled = false;
            }

            _Global.basSysPara.SqlHelp = APP.SqlHelp;
            _Global.basSysPara.PORT_CODE = APP.PORT_CODE;
            _Global.basSysPara.UserID = APP.User_ID;

            bzExpBill = new bizExpBill(_Global.basSysPara);

            #region 初始化基础数据
            etyCodeRef eyCode = new etyCodeRef();
            eyCode.ITEM = "BUSS_TYPE";
            _Global.ilBussType = bzExpBill.GetCodeRef(eyCode);
            _Global.ilClient = bzExpBill.GetClient();

            #endregion

            InitForm();
        }


        private void InitForm()
        {
            //省份
            _Global.ilSF = bzExpBill.GetBaseTableCodeName("B_SF", 0, true);
            //业务类型
            _Global.ilYwType = bzExpBill.GetBaseTableCodeName("b_yw_type", 0, false);
            //市
            _Global.ilCity = bzExpBill.GetBaseTableCodeName("B_CITY", 0, true);
            //院
            _Global.ilQX = bzExpBill.GetBaseTableCodeName("B_QX", 0, true);

        }
    }
}
